﻿using System;
using System.Collections.Generic;
using System.Text;
using PacMan3D.Utils;
using Tao.OpenGl;
using Tao.FreeGlut;

namespace PacMan3D.Objects
{
    public class Food : IRenderable, ICollidable
    {
        public Point3D Position {get; private set;}

        private RGBAColor Color;
        private float RadiusSize;

        private int Slices = 15;
        private int Stacks = 15;

        /// 
        /// Food Material 
        /// 
        private float[] Specular = { 1.0f, 1.0f, 1.0f, 1.0f };
        private int Shininess = 70;

        private int DisplayListId = 0;

        public Food(Point3D position, float radiusSize)
        {
            this.Position = position;
            this.Position.Y = radiusSize / 4.0f;
            this.RadiusSize = radiusSize / 12.0f;
            this.Color = new RGBAColor(StandardColors.Yellow, 1.0f);

            this.DisplayListId = Gl.glGenLists(1);
            Gl.glNewList(this.DisplayListId, Gl.GL_COMPILE);
            Glut.glutSolidSphere(this.RadiusSize, this.Slices, this.Stacks);
            Gl.glEndList();
        }

        public override void DrawObject()
        {
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glPushMatrix();
                Gl.glTranslatef(this.Position.X, this.Position.Y, this.Position.Z);
                Gl.glColor4f(this.Color.Red, this.Color.Green, this.Color.Blue, this.Color.Alpha);
                Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, this.Specular);
                Gl.glMateriali(Gl.GL_FRONT, Gl.GL_SHININESS, this.Shininess);
                Gl.glCallList(this.DisplayListId);
            Gl.glPopMatrix();
            Gl.glDisable(Gl.GL_LIGHTING);            
        }

        #region ICollidable Members
        
        public float Size
        {
            get { return this.RadiusSize; }
        }

        #endregion
    }
}
